package com.example.calendar.data.repository

import com.example.calendar.data.local.dao.CategoryDao
import com.example.calendar.data.model.Category
import com.example.calendar.data.model.CategoryType
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

/**
 * Interface for category repository operations
 */
interface CategoryRepository {
    suspend fun addCategory(category: Category): String
    suspend fun updateCategory(category: Category)
    suspend fun deleteCategory(categoryId: String)
    fun getCategoryById(categoryId: String): Flow<Category?>
    fun getAllCategories(): Flow<List<Category>>
    fun getCategoriesByType(type: CategoryType): Flow<List<Category>>
    fun getCategoriesByTypes(types: List<CategoryType>): Flow<List<Category>>
    fun getDefaultCategoryForType(type: CategoryType): Flow<Category?>
}

/**
 * Implementation of CategoryRepository that works with the Room database
 */
@Singleton
class CategoryRepositoryImpl @Inject constructor(
    private val categoryDao: CategoryDao
) : CategoryRepository {
    
    override suspend fun addCategory(category: Category): String {
        categoryDao.insertCategory(category)
        return category.id
    }
    
    override suspend fun updateCategory(category: Category) {
        categoryDao.updateCategory(category)
    }
    
    override suspend fun deleteCategory(categoryId: String) {
        categoryDao.softDeleteCategory(categoryId)
    }
    
    override fun getCategoryById(categoryId: String): Flow<Category?> {
        return categoryDao.getCategoryById(categoryId)
    }
    
    override fun getAllCategories(): Flow<List<Category>> {
        return categoryDao.getAllCategories()
    }
    
    override fun getCategoriesByType(type: CategoryType): Flow<List<Category>> {
        return categoryDao.getCategoriesByType(type)
    }
    
    override fun getCategoriesByTypes(types: List<CategoryType>): Flow<List<Category>> {
        return categoryDao.getCategoriesByType(types)
    }
    
    override fun getDefaultCategoryForType(type: CategoryType): Flow<Category?> {
        return categoryDao.getDefaultCategoryForType(type)
    }
} 